package google.usingblobstore;

import java.io.IOException;
import javax.servlet.http.*;

/**
 * Handles requests to get average tests scores using Datastore.
 * 
 * @author eschoeffler@google.com (Eric Schoeffler)
 */
@SuppressWarnings("serial")
public class DatastoreFilterServlet extends HttpServlet {
  
  private ScoreCalculator scoreCalculator;
  
  public DatastoreFilterServlet() {
    scoreCalculator = new DatastoreScoreCalculator();
  }
  
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json");
    ScoresData result = scoreCalculator.averageByHair(req.getParameter("hair_color"));
    resp.getWriter().println(
      "[" + result.time + "," + result.matches + "," + result.average + "]");
  }
}
